Skip to content

[#10733] fix(core): Correct DBCP2 connection pool settings to avoid cold-start connection overhead#10734

Open
yuqi1129 wants to merge 1 commit intoapache:mainfrom
yuqi1129:fix_dbcp2_pool_config
Open

[#10733] fix(core): Correct DBCP2 connection pool settings to avoid cold-start connection overhead#10734
yuqi1129 wants to merge 1 commit intoapache:mainfrom
yuqi1129:fix_dbcp2_pool_config

Conversation

@yuqi1129
Copy link
Copy Markdown
Contributor

@yuqi1129 yuqi1129 commented Apr 10, 2026

What changes were proposed in this pull request?

Two hardcoded DBCP2 settings in SqlSessionFactoryHelper are corrected:

  • minIdle: 05
  • minEvictableIdleTimeMillis: 1000 ms (1 s) → 30000 ms (30 s, via Duration.ofSeconds(30).toMillis())

Why are the changes needed?

Fix: #10733

The evictor thread runs every 10 minutes (timeBetweenEvictionRunsMillis = 10 min). With minEvictableIdleTimeMillis = 1 s, every idle connection is eligible for eviction on each evictor run. After any quiet period ≥ 10 minutes, all connections are evicted. Combined with minIdle = 0, the pool shrinks to zero, so the next burst of requests must pay a DB connection-establishment cost (TCP handshake + auth, ~20–100 ms on MySQL/PostgreSQL) before they can execute.

1000 ms also reads as an accidental dev/test value. Replacing it with Duration.ofSeconds(30).toMillis() makes the intent explicit and guards against over-aggressive eviction if the evictor interval is ever shortened.

Does this PR introduce any user-facing change?

No. These are internal connection pool settings with no API or config surface change.

How was this patch tested?

./gradlew :core:test -PskipITs

…leTimeMillis=1s

- minIdle: 0 → 5 to keep warm connections ready and avoid cold-start
  latency after idle periods. With minIdle=0, the evictor (running every
  10 min) drains the pool to zero, forcing connection re-establishment
  on the next request.
- minEvictableIdleTimeMillis: 1000ms → Duration.ofSeconds(30).toMillis()
  (30 s). 1 second was effectively a no-op guard since the evictor only
  runs every 10 minutes, and reads as a suspicious dev/test value.
  Using Duration.ofSeconds(30) makes the intent explicit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 10, 2026 08:13
@yuqi1129 yuqi1129 changed the title [#10733] fix(core): Fix DBCP2 connection pool minIdle=0 and minEvictableIdleTimeMillis=1s [#10733] fix(core): Correct DBCP2 connection pool settings to avoid cold-start connection overhead Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the DBCP2 connection pool configuration used by SqlSessionFactoryHelper to reduce cold-start latency after idle periods by keeping a small warm pool and avoiding overly aggressive eviction.

Changes:

  • Increase BasicDataSource minIdle from 0 to 5 to prevent the pool from shrinking to zero.
  • Increase minEvictableIdleTimeMillis from 1000ms to 30s using Duration for clarity.

Comment on lines 90 to +99
dataSource.setMaxTotal(config.get(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_MAX_CONNECTIONS));
dataSource.setMaxIdle(5);
dataSource.setMinIdle(0);
dataSource.setMinIdle(5);
dataSource.setLogAbandoned(true);
dataSource.setRemoveAbandonedOnBorrow(true);
dataSource.setRemoveAbandonedTimeout(60);
dataSource.setTimeBetweenEvictionRunsMillis(Duration.ofMillis(10 * 60 * 1000L).toMillis());
dataSource.setTestOnBorrow(true);
dataSource.setTestWhileIdle(true);
dataSource.setMinEvictableIdleTimeMillis(1000);
dataSource.setMinEvictableIdleTimeMillis(Duration.ofSeconds(30).toMillis());
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pool settings change (minIdle/minEvictableIdleTimeMillis) isn’t currently covered by a unit assertion. Please add/extend a test (e.g., in TestSqlSession#testInit) to verify the configured BasicDataSource values so this behavior change is protected from regressions.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those changes do not need UTs to cover it.

Comment on lines 90 to 93
dataSource.setMaxTotal(config.get(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_MAX_CONNECTIONS));
dataSource.setMaxIdle(5);
dataSource.setMinIdle(0);
dataSource.setMinIdle(5);
dataSource.setLogAbandoned(true);
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idle-size value 5 is now duplicated between setMaxIdle(5) and setMinIdle(5). Consider defining a single constant (or deriving one from the other) to prevent future mismatches when tuning the pool.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown

Code Coverage Report

Overall Project 65.18% +0.02% 🟢
Files changed 95.08% 🟢

Module Coverage
aliyun 1.73% 🔴
api 47.14% 🟢
authorization-common 85.96% 🟢
aws 1.1% 🔴
azure 2.6% 🔴
catalog-common 10.2% 🔴
catalog-fileset 80.02% 🟢
catalog-hive 80.98% 🟢
catalog-jdbc-clickhouse 79.06% 🟢
catalog-jdbc-common 42.89% 🟢
catalog-jdbc-doris 80.28% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.23% 🟢
catalog-jdbc-oceanbase 78.38% 🟢
catalog-jdbc-postgresql 82.05% 🟢
catalog-jdbc-starrocks 78.27% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 45.07% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 87.16% 🟢
catalog-lakehouse-paimon 77.71% 🟢
catalog-model 77.72% 🟢
cli 44.51% 🟢
client-java 77.63% 🟢
common 49.35% 🟢
core 81.41% +0.04% 🟢
filesystem-hadoop3 76.97% 🟢
flink 40.55% 🟢
flink-runtime 0.0% 🔴
gcp 14.2% 🔴
hadoop-common 10.39% 🔴
hive-metastore-common 45.82% 🟢
iceberg-common 50.73% 🟢
iceberg-rest-server 65.82% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 23.88% 🔴
lance-rest-server 57.84% 🟢
lineage 53.02% 🟢
optimizer 82.95% 🟢
optimizer-api 21.95% 🔴
server 85.89% 🟢
server-common 70.3% 🟢
spark 32.79% 🔴
spark-common 39.09% 🔴
trino-connector 33.83% 🔴
Files
Module File Coverage
core SqlSessionFactoryHelper.java 95.08% 🟢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] Fix DBCP2 connection pool: minIdle=0 and minEvictableIdleTimeMillis=1s cause cold-start latency

2 participants